#include "split.hpp"
#include <vector>
#include <cstring>

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

char _data[30][20] = {0};
int count = 0;

TEST_CASE("split1")
{
    char _sentence[] = "$qess,123,,f3,*3\r\n";
    memset(_data, 0, sizeof(_data));
    count = 0;
    split_string(_sentence, _data, &count);
    REQUIRE(count == 6);
    REQUIRE(!strcmp(_data[0], "$qess"));
    REQUIRE(!strcmp(_data[1], "123"));
    REQUIRE(!strcmp(_data[2], ""));
    REQUIRE(!strcmp(_data[3], "f3"));
    REQUIRE(!strcmp(_data[4], ""));
    REQUIRE(!strcmp(_data[5], "3\r\n"));
}

TEST_CASE("split2")
{
    char _sentence[] = "$qess,,,f3,*99\r\n";
    memset(_data, 0, sizeof(_data));
    count = 0;
    split_string(_sentence, _data, &count);
    REQUIRE(count == 6);
    REQUIRE(!strcmp(_data[0], "$qess"));
    REQUIRE(!strcmp(_data[1], ""));
    REQUIRE(!strcmp(_data[2], ""));
    REQUIRE(!strcmp(_data[3], "f3"));
    REQUIRE(!strcmp(_data[4], ""));
    REQUIRE(!strcmp(_data[5], "99\r\n"));
}

TEST_CASE("split3")
{
    char _sentence[] = "$qess,1,2,,f3,*99\r\n";
    memset(_data, 0, sizeof(_data));
    count = 0;
    split_string(_sentence, _data, &count);
    REQUIRE(count == 7);
    REQUIRE(!strcmp(_data[0], "$qess"));
    REQUIRE(!strcmp(_data[1], "1"));
    REQUIRE(!strcmp(_data[2], "2"));
    REQUIRE(!strcmp(_data[3], ""));
    REQUIRE(!strcmp(_data[4], "f3"));
    REQUIRE(!strcmp(_data[5], ""));
    REQUIRE(!strcmp(_data[6], "99\r\n"));
}

TEST_CASE("split4")
{
    char _sentence[] = "a*";
    memset(_data, 0, sizeof(_data));
    count = 0;
    split_string(_sentence, _data, &count);
    REQUIRE(count == 2);
    REQUIRE(!strcmp(_data[0], "a"));
    REQUIRE(!strcmp(_data[1], ""));
}